<template>
    <tableTmp name="bizAudit"
              title="业务单审核"
              :list="auditOrder"
              class="bizAudit"
              :total="0"
              @change="changePage">
        <template slot="table"
                  slot-scope="scope">
            <el-button type="text"
                       :disabled="scope.props.row.status !== '1'"
                       @click.stop="audit(scope, '2')">通过</el-button>
            <el-button type="text"
                       :disabled="scope.props.row.status !== '1'"
                       @click.stop="audit(scope, '3')"
                       class="danger">未通过</el-button>
        </template>
    </tableTmp>
</template>
<script>
export default {
    name: 'bizAudit',
    data() {
        return {
        }
    },
    computed: {
        auditOrder() {
            return this.$store.state.order.auditOrder
        },
        pageSet() {
            return this.$store.state.order.auditPageSet
        }
    },
    methods: {
        init() {
            this.$store.dispatch('getAuditOrder', {
                page: '1'
            })
        },
        changePage(curPage) {
            console.log(curPage)
        },
        audit({ props }, status) {
            const fn = (meg = '') => {
                this.$store.dispatch('auditOrder', {
                    id: props.row.id,
                    meg,
                    status
                }).then(data => {
                    const message = {
                        '2': '通过',
                        '3': '未通过'
                    }
                    this.$message({
                        type: 'success',
                        message: `已审核 —— 审核${message[status]}`
                    })
                })
            }
            if (status === '3') {
                this.$prompt('请输入不通过原因', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消'
                }).then(({ value }) => {
                    fn(value)
                })
            } else {
                fn()
            }
        }
    },
    created() {
        this.init()
    }
}
</script>
<style lang='less'>
.bizAudit {
    .el-button--text.danger {
        color: #ed7d74;
    }
    .el-button--text.is-disabled,
    .el-button--text.is-disabled:focus,
    .el-button--text.is-disabled:hover {
        color: #c0c4cc;
    }
}
.bizAudit-btn {
    cursor: pointer;
    padding: 10px;
}
</style>
